//
//  LSZInviteFriendsViewController.m
//  JKFuYinProject
//
//  Created by 九酷 on 2018/8/28.
//  Copyright © 2018年 LC. All rights reserved.
//

#import "LSZInviteFriendsViewController.h"

@interface LSZInviteFriendsViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong) UITableView * tableViewInviteFriends;

@end

@implementation LSZInviteFriendsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"邀请好友";
    [self.tableViewInviteFriends registerClass:[LSZInvireFriendsTableViewCell class] forCellReuseIdentifier:@"LSZInvireFriendsTableViewCell"];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat height = [LSZSpecialPackaging initWithReturnsthesizeOf:50 :5];
    return height;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.0001;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    LSZInvireFriendsTableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:@"LSZInvireFriendsTableViewCell" forIndexPath:indexPath];
    if(indexPath.row == 0){
        cell.imageViewCover.image = [UIImage imageNamed:@"二维码_微信"];
        cell.labelCover.text = @"邀请微信好友";
    }else{
        cell.imageViewCover.image = [UIImage imageNamed:@"我的_QQ"];
        cell.labelCover.text = @"邀请QQ好友";
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; //显示最右边的箭头
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    @weakify(self)
    NSString *url = [NSString stringWithFormat:@"%@/extension/create_img",http_toutiao];
    [kNetworkTool POSTFuYinWithUrlString:url input:@{} success:^(NSDictionary * dict) {
        @strongify(self)
        NetWorkModel *netWorkModel = [NetWorkModel yy_modelWithJSON:dict];
        NSDictionary *dic = netWorkModel.data;
        if (netWorkModel.status == 1) {
            if (indexPath.row == 0) {NSLog(@"邀请微信好友");
                if ([ShareSDK isClientInstalled:SSDKPlatformTypeWechat] == NO) {
                    [SVProgressHUD showErrorWithStatus:@"未安装微信"];
                    return;
                }
                [self shareYaoQingMessageWithImageArray:@[dic[@"url"]] type:SSDKPlatformSubTypeWechatSession];
            }else{NSLog(@"邀请QQ好友");
                if ([ShareSDK isClientInstalled:SSDKPlatformTypeQQ] == NO) {
                    [SVProgressHUD showErrorWithStatus:@"未安装QQ"];
                    return;
                }
                [self shareYaoQingMessageWithImageArray:@[dic[@"url"]] type:SSDKPlatformSubTypeQQFriend];
            }
        }else{
            [self setStringWarning:netWorkModel.msg];
        }
    } failure:^(NSError * error) {
        NSLog(@"error = %@", error);
    }];
}
- (void)shareYaoQingMessageWithImageArray:(NSArray *)imageArray type:(SSDKPlatformType)type{
    //1、创建分享参数
    if (imageArray) {
    }else{
        imageArray = @[[UIImage imageNamed:@"我的_设置_关于"]];
    }
    //
    NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
    [shareParams SSDKSetupShareParamsByText:nil
                                     images:imageArray
                                        url:nil
                                      title:nil
                                       type:SSDKContentTypeImage];
    //进行分享
    [ShareSDK share:type //传入分享的平台类型
         parameters:shareParams
     onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) {
         
     }];
}

-(UITableView *)tableViewInviteFriends
{
    if (_tableViewInviteFriends == nil) {
        _tableViewInviteFriends = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight) style:UITableViewStyleGrouped];
        _tableViewInviteFriends.delegate = self;
        _tableViewInviteFriends.dataSource = self;
        _tableViewInviteFriends.separatorColor = divider;
        _tableViewInviteFriends.estimatedRowHeight =0;
        _tableViewInviteFriends.estimatedSectionFooterHeight =0;
        _tableViewInviteFriends.estimatedSectionHeaderHeight =0;
        _tableViewInviteFriends.separatorInset = UIEdgeInsetsMake(0, 20, 0, 20);
        _tableViewInviteFriends.separatorStyle = UITableViewCellSeparatorStyleNone;
        [self.view addSubview:_tableViewInviteFriends];
    }
    return _tableViewInviteFriends;
}

@end
